<template>
  <el-form ref="ruleFormRef" :model="form" :rules="rules" class="full loginBox list-b-16" size="large">
    <div class="loginBox-main">
      <div class="loginBox-mainL">
        <div>
          <p>Hi,您好！</p>
          <p>欢迎使用印务ERP</p>
        </div>
      </div>
      <div class="loginBox-mainR">
        <div class="loginBox-box list-b-16">
          <div class="loginBox-logo flex-c-center-center">
            <h2>欢迎您登录系统</h2>
          </div>
          <ElFormItemBox label="" prop="loginAccount">
            <ElInputBox :data="form" dataName="loginAccount" icon="User" placeholder="请输入账号" @keyupBtn="loginBtn()">
            </ElInputBox>
          </ElFormItemBox>
          <ElFormItemBox label="" prop="loginPassWord">
            <ElInputBox :data="form" dataName="loginPassWord" icon="Lock" placeholder="请输入密码" type="password"
              showPassword @keyupBtn="loginBtn()"> </ElInputBox>
          </ElFormItemBox>
          <el-button type="primary" class="wAuto" @click="loginBtn"> 立即登录 </el-button>
        </div>
      </div>
    </div>
    <div class="loginBox-foot flex-center-center list-r-16">
      <span>技术支持：影彩信息科技有限公司</span>
      <!-- <span>备案号：渝ICP备1803211号-2</span> -->
    </div>
  </el-form>
</template>
<script setup lang="ts">
import { getCurrentInstance, reactive, ref } from 'vue';
const { proxy } = getCurrentInstance() as any;

import { setUser } from '@/utils/user.ts';
//获取路由
import { useRouter } from 'vue-router';
const router = useRouter();

const ruleFormRef = ref(null);
const form = reactive({
  loginAccount: '',
  loginPassWord: '',
});
const rules = reactive({
  loginAccount: [{ required: true, message: '账号必填', trigger: 'blur' }],
  loginPassWord: [{ required: true, message: '账号必填', trigger: 'blur' }],
});
const loginBtn = () => {
  let _ruleFormRef = ruleFormRef.value;
  if (!_ruleFormRef) return;
  _ruleFormRef.validate(async (valid: any) => {
    if (valid) {
      proxy.$api.SystemManage.ExcuteAdminLogin(form).then((res: any) => {
        proxy.$com.message('登录成功');
        proxy.$com.setItem('apiToken', res.apiToken);
        proxy.$com.setItem('loginToken', res.loginToken);
        proxy.$com.setItem('authenticationToken', res.authenticationToken);
        setUser(res)
        router.push('/');
      });
    } else {
    }
  });
};
onBeforeMount(() => { });

onMounted(() => {
  localStorage.clear();
});
</script>

<style scoped lang="scss">
.loginBox {
  background: #{$primary} url('@/images/bg.jpeg') no-repeat center;
  background-size: cover;
  color: #{$white};
  display: flex;
  flex-direction: column;
  padding: 40px 100px;

  .loginBox-box {
    background: #{$white};
    color: #{$text};
    padding: 68px 54px;
    border-radius: 8px;
  }

  @include responstTo('tv') {
    .loginBox-head {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 32px;
    }

    .loginBox-main {
      flex: 1;
      display: flex;
      justify-content: space-between;
      overflow: hidden;

      .loginBox-mainL {
        display: flex;
        align-items: center;
        font-size: 42px;
      }

      .loginBox-mainR {
        display: flex;
        align-items: center;
        justify-content: center;

        .loginBox-box {
          box-shadow:
            0 0.125rem 0.125rem rgba(10, 16, 20, 0.24),
            0 0 0.125rem rgba(10, 16, 20, 0.12);
          width: 440px;
        }
      }

      .loginBox-logo {
        img {
          max-height: 50px;
          max-width: 220px;
        }
      }
    }

    .el-link__inner {
      color: #{$white};
      font-weight: normal;
    }
  }

  @include responstTo('pad') {
    &.loginBox {
      padding: 16px;
      display: flex;
      align-items: center;
      justify-content: center;

      .loginBox-mainL {
        text-align: center;
        font-size: 30px;
        margin-bottom: 30px;
      }

      .loginBox-logo {
        display: none;
      }

      .loginBox-box {
        padding: 32px;
        width: 360px;
      }
    }
  }

  @include responstTo('phone') {
    &.loginBox {
      padding: 16px;
      display: flex;
      align-items: center;
      justify-content: center;

      .loginBox-mainL {
        display: none;
      }

      .loginBox-logo {
        display: none;
      }

      .loginBox-box {
        background: none;
        color: #{$white};
        padding: 0;
      }

      .loginBox-foot {
        font-size: 10px;
      }
    }
  }
}
</style>
